# list列表定义
list1 = [1,2,3,4,5]
list2 = ['a','b','c','d','e']
list3 = [1,'a',True]   
print(list1) 
# 遍历列表
for i in list1:
    print(i)

# 添加元素
list1.append(6)
print(list1)
# 删除元素
# 在前删除（下标）
list1.pop(0)
print(list1)
# 删除元素（值）
list1.remove(6)
print(list1)
# 修改元素
list1[0] = 10
print(list1) #  [10, 3, 4, 5]

# 列表切片
#   [起始位置:结束位置:步长]
# [10, 3, 4, 5]
print(list1[0:3:1]) #  print(list1[0:3])
print(list1[0:3:2]) 
# [10, 3, 4, 5]
print(list1[::-1]) # 逆序 5 4 3 10
print(list1[::-2]) # 逆序2步长 4 3 

print(list1[-2:]) # 倒数第二个元素

# 列表长度
print(len(list1)) # 4

# 列表合并
# 定义列表2
list2 = [1,2,3,4,5]
# 定义列表2
list3 = ['a','b','c','d','e']
# 合并列表
list4 = list2 + list3
list4.extend(list2)
print(list4)
list5 = list2 * 2
print(list5)
# 列表排序
list6 = [5,2,2,4,1]
list6.sort()
print(list6)
# 列表反转
list6.reverse()
print(list6)

# 元组tuple
tuple1 = (1,2,3,4,5)
tuple2 = ('a','b','c','d','e')
tuple3 = (1,'a',True)
print(tuple1)
# 遍历元组
for i in tuple1:
    print(i)

# 元组不能修改
# tuple1[0] = 10

# 集合set
set1 = {1,2,3,4,5}
set2 = {'a','b','c','d','e'}
set3 = {1,'a',True}
print(set2)
# 遍历集合
for i in set2:
    print(i)

# 集合不能修改
# set1[0] = 10

# 集合添加数据
set2.add('f')
set2.add('g')
set2.add('h')
print(set2)
set2.remove('h')
# 默认去重，加入失败
set2.add('g')
print(set2)

# 集合运算
# 并集
set1 = {1,2,3,4,5,'a','b','c'}
set2 = {'a','b','c','d','e'}
set3 = set1 | set2
print(set3)
# 交集
set3 = set1 & set2
print(set3)
# 差集
set3 = set1 - set2
print(set3)
# 对称差集
set3 = set1 ^ set2
print(set3)

print("------------------------------------------")
# 字典dict
dict1 = {'name':'张三','age':18,'gender':'男'}
print(dict1['name'])
print(dict1['age'])
print(dict1['gender'])
# 遍历字典
print(dict1.keys())
print(dict1.values())
print(dict1.items())
# key 遍历
for key in dict1:
    print(key, dict1[key])

# entry 遍历
for key,value in dict1.items():
    print(key,value)

#修改字典
dict1['name'] = '李四'
print(dict1)
# 添加字典
dict1['address'] = '北京'
print(dict1)
# 删除字典
del dict1['address']
print(dict1)
